package org.grayrabbit.cms.entity;

import java.io.UnsupportedEncodingException;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "CMS_KEYWORDS")
public class Keywords implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private String keywordsId;
	private String keywords;
	private String pinyin;
	private String firstLetter;
	private String splitWords;
	private Boolean isEnable;
	private Set<KeywordsRecommend> keywordsRecommends = new HashSet<KeywordsRecommend>(0);
	
	//二期
	private Integer clickNumber;//点击量
	//end

	public Keywords() {
	}

	public Keywords(String keywordsId) {
		this.keywordsId = keywordsId;
	}

	public Keywords(String keywordsId, String keywords, String firstLetter, String splitWords, Boolean isEnable, Set<KeywordsRecommend> keywordsRecommends) {
		this.keywordsId = keywordsId;
		this.keywords = keywords;
		this.firstLetter = firstLetter;
		this.splitWords = splitWords;
		this.isEnable = isEnable;
		this.keywordsRecommends = keywordsRecommends;
	}

	@Id
	@Column(name = "KEYWORDS_ID", unique = true, nullable = false, length = 32)
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "uuid") 	
	public String getKeywordsId() {
		return this.keywordsId;
	}

	public void setKeywordsId(String keywordsId) {
		this.keywordsId = keywordsId;
	}

	@Column(name = "KEYWORDS", length = 200)
	public String getKeywords() {
		return this.keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	@Column(name = "FIRST_LETTER", length = 32)
	public String getFirstLetter() {
		return this.firstLetter;
	}

	public void setFirstLetter(String firstLetter) {
		this.firstLetter = firstLetter;
	}

	@Column(name = "SPLIT_WORDS", length = 64)
	public String getSplitWords() {
		return this.splitWords;
	}

	public void setSplitWords(String splitWords) {
		this.splitWords = splitWords;
	}

	@Column(name = "ISENABLE", precision = 1, scale = 0)
	public Boolean getIsEnable() {
		return this.isEnable;
	}

	public void setIsEnable(Boolean isEnable) {
		this.isEnable = isEnable;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "keywords")
	public Set<KeywordsRecommend> getKeywordsRecommends() {
		return this.keywordsRecommends;
	}

	public void setKeywordsRecommends(Set<KeywordsRecommend> keywordsRecommends) {
		this.keywordsRecommends = keywordsRecommends;
	}

	@Column(name = "PINYIN", length = 100)
	public String getPinyin() {
		return pinyin;
	}
	
	public void setPinyin(String pinyin) {
		this.pinyin = pinyin;
	}
	
	
	@Column(name = "CLICK_NUMBER", precision = 6, scale = 0)
	public Integer getClickNumber() {
		return clickNumber;
	}

	public void setClickNumber(Integer clickNumber) {
		this.clickNumber = clickNumber;
	}

	@Transient
	public String getWord2UTF8(){
		try {
			return java.net.URLEncoder.encode(keywords,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return keywords;
		}
	}

}
